﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Prism.Events;
using SoonCode.Core;
using SoonCode.FocusTest.Events;
using SoonCode.FocusTest.Models;

namespace SoonCode.FocusTest.Views
{
    /// <summary>
    /// TestItemG.xaml 的交互逻辑
    /// </summary>
    public partial class TestItemG : UserControl
    {
        private IEventAggregator aggregator;
        public TestItemG(IEventAggregator aggregator)
        {
            this.aggregator = aggregator;
            InitializeComponent();
            aggregator.GetEvent<StudentAnswerEvent>().Subscribe(StudentAnswer);
            
        }
        public void StudentAnswer(EventInfo info)
        {
            if (info == null || info.Type != "itemG")
            { return; }

            Canvas canvas = (Canvas)info.Data["canvas"];
            if (canvas == null)
            {
                return;
            }
            Canvas element = ((Canvas)info.Data["canvas"]);
            TeacherCanvas.Width = element.ActualWidth;
            TeacherCanvas.Height = element.ActualHeight;
            TeacherCanvas.UpdateLayout();
            TeacherCanvas.Children.Clear();
            foreach (UIElement el in element.Children)
            {
                string xaml = System.Windows.Markup.XamlWriter.Save(el);
                TeacherCanvas.Children.Add(System.Windows.Markup.XamlReader.Parse(xaml) as UIElement);
            }
        }
    }
}
